<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0"><meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" /> 
        <title>Welcome to Design Zone......</title>
        <link rel="stylesheet" type="text/css" href="../../scripts/ext/resources/css/ext-all.css" />
        <link rel="stylesheet" type="text/css" href="../../scripts/ext/resources/css/file-upload.css" />
        <link rel="stylesheet" type="text/css" href="../../styles/dzbase.css" />
        <script type="text/javascript" src="../../scripts/ext/adapter/ext-base.js">
        </script>
        <script type="text/javascript" src="../../scripts/ext/ext-all.js">
        </script>
        <script type="text/javascript" src="../../scripts/grid/GroupSummary.js">
        </script>
        <script type="text/javascript" src="../../scripts/grid/RowExpander.js">
        </script>
        <script type="text/javascript" src="../../scripts/menu/EditableItem.js">
        </script>
        <script type="text/javascript" src="../../scripts/menu/RangeMenu.js">
        </script>
        <script type="text/javascript" src="../../scripts/grid/GridFilters.js">
        </script>
        <script type="text/javascript" src="../../scripts/grid/filter/Filter.js">
        </script>
        <script type="text/javascript" src="../../scripts/grid/filter/StringFilter.js">
        </script>
        <script type="text/javascript" src="../../scripts/grid/filter/ListFilter.js">
        </script>
        <script type="text/javascript" src="../../scripts/i18nMessage.js">
        </script>
        <script type="text/javascript" src="../../scripts/utils.js">
        </script>
        <script type="text/javascript">
            var idValue = getPrarmeterValue(window.location, 'id');
            var startPage = getPrarmeterValue(window.location, 'startPage');
            var input = getPrarmeterValue(window.location, 'input');
            
            var piMessage = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=ui.productidentification');
            var azMessage = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=ui.accessoryzip');
            var aoMessage = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=ui.accessoryothers');
			var orderMessage = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=ui.order');
			var colorMessage = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=ui.pantonecolor');
			var fMessage = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=ui.factory');
			var fcMessage = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=ui.francecustomer');
            var referenceMessage = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=ui.reference');
            var dzColorMessage = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=ui.dzcolor');
            var message = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=message');
            
			var ctYesnoXmlLoader = new xmlLoader('../../servlet/CodeTableServlet?name=CtYesno');
            
            var ctYesnoStore = new Ext.data.Store({
                   
                    reader: new Ext.data.XmlReader({
                        record: 'item',
                        id: 'code',
                        totalRecords: 'itemTotal'
                    }, [
                    'code', 'description']),
					data: ctYesnoXmlLoader.getXml()
                });
                
            var isDZBuyCombo = new Ext.form.ComboBox({
					fieldLabel: message.get('message.edit.isdzbuy'),
					id: 'isDZBuy',
					name: 'isDZBuy',
					editable: false,
					valueField: 'code',
				    store: ctYesnoStore,
				    anchor: '76%',
					width: '80%',
				    displayField:'description',
				    triggerAction: 'all',
				    emptyText: message.get('message.combo.pleaseselect'),
					allowBlank: false,
                    blankText: message.get('message.edit.noblank'),
				    selectOnFocus:true,
					mode: 'local'
				});            
            var piZipForm
            var piZipStore;
            var piZipGrid;
            
            var piXMLReader = new Ext.data.XmlReader({
                   record: 'item'
               }, [{
                   name: 'id',
                   mapping: 'id'
               }, {
                   name: 'ctProductFamily',
                   mapping: 'ctProductFamily'
               }, {
                   name: 'ctMachineType',
                   mapping: 'ctMachineType'
               }, {
                   name: 'type',
                   mapping: 'type'
               }, {
                   name: 'orderNumber',
                   mapping: 'orderNumber'
               }, {
                   name: 'yarnNumber',
                   mapping: 'yarnNumber'
               }, {
                   name: 'ctDesignType',
                   mapping: 'ctDesignType'
               }, {
                   name: 'style',
                   mapping: 'style'
               }, {
                   name: 'customerLinkman',
                   mapping: 'customerLinkman'
               }, {
                   name: 'model',
                   mapping: 'model'
               }, {
                   name: 'ctSeasonNumber',
                   mapping: 'ctSeasonNumber'
               }, {
                   name: 'ctSeasonNumberCode',
                   mapping: 'ctSeasonNumberCode'
               }, {
                   name: 'reference',
                   mapping: 'reference'
               }, {
                   name: 'createDate',
                   mapping: 'createDate'
               }, {
                   name: 'ctVersion',
                   mapping: 'ctVersion'
               }, {
                   name: 'patronageNumer',
                   mapping: 'patronageNumer'
               }, {
                   name: 'front',
                   mapping: 'front'
               }, {
                   name: 'back',
                   mapping: 'back'
               }, {
                   name: 'sleeves',
                   mapping: 'sleeves'
               }, {
                   name: 'bottomThrum',
                   mapping: 'bottomThrum'
               }, {
                   name: 'sleevesThrum',
                   mapping: 'sleevesThrum'
               }, {
                   name: 'necklineThrum',
                   mapping: 'necklineThrum'
               }, {
                   name: 'needle',
                   mapping: 'needle'
               }, {
                   name: 'weight',
                   mapping: 'weight'
               }, {
                   name: 'comment',
                   mapping: 'comment'
               }, {
                   name: 'customerID',
                   mapping: 'customerID'
               }, {
                   name: 'photoName',
                   mapping: 'photoName'
               }, {
                   name: 'chartName',
                   mapping: 'chartName'
               }, {
                   name: 'biMeasureSpecificationId',
                   mapping: 'biMeasureSpecificationId'
               }, {
                   name: 'biMeasureSpecificationName',
                   mapping: 'biMeasureSpecificationName'
               }, {
                   name: 'yarnName',
                   mapping: 'yarnName'
               }, {
                   name: 'frontPhotoName',
                   mapping: 'frontPhotoName'
               }, {
                   name: 'backPhotoName',
                   mapping: 'backPhotoName'
               }, {
                   name: 'photoName',
                   mapping: 'photoName'
               }, {
                   name: 'chartName',
                   mapping: 'chartName'
               }, {
                   name: 'ctCollarType',
                   mapping: 'ctCollarType'
               }, {
                   name: 'customerName',
                   mapping: 'customerName'
               }, {
                   name: 'customerDepartment',
                   mapping: 'customerDepartment'
               }, {
                   name: 'referenceAs',
                   mapping: 'referenceAs'
               }, {
                   name: 'createDate',
                   mapping: 'createDate'
               }]);
                
              var piXmlLoader = new xmlLoader('../../servlet/ProductIdentificationServlet?action=11&id=' + idValue);
              
              var piRecord = piXMLReader.readRecords(piXmlLoader.getXml()).records[0];
              
              var itemTplMarkup = ['<table cellspacing="0" id="the-table" style="width: 100%;"><tbody>',
								 '<tr><td style="background:#eeeeee; width: 15%;">',
								 message.get('message.list.id'), '</td><td>{id}</td>', 
								 '<td style="background:#eeeeee;width: 15%;">', 
								 piMessage.get('ui.productidentification.style'), 
								 '</td><td>{style}</td><td style="background:#eeeeee;">', 
								 piMessage.get('ui.productidentification.seasonnumber'), 
								 '</td><td>{ctSeasonNumber}</td>', '<td style="background:#eeeeee;">', 
								 referenceMessage.get('ui.reference.reference'), 
								 '</td><td>{reference}</td></tr>', 
								 
								 
								 '<tr><td style="background:#eeeeee;">', 
								message.get('message.edit.createdate') + "(d/m/Y)",
								 '</td><td>{createDate}</td><td style="background:#eeeeee;">', 
								piMessage.get('ui.productidentification.designtype'), 
								 '</td><td>{ctDesignType}</td><td style="background:#eeeeee;">', 
								 piMessage.get('ui.productidentification.chartversion'), 
								 '</td><td>{ctVersion}</td><td style="background:#eeeeee;">', 
								 piMessage.get('ui.productidentification.referenceas'), 
								 '</td><td>{referenceAs}</td></tr>',
								 
								 '<tr><td style="background:#eeeeee;">', 
								 referenceMessage.get('ui.reference.weight') + '(Kg)', 
								 '</td><td>{weight}</td><td style="background:#eeeeee;">', 
								 message.get('message.edit.collar'), 
								 '</td><td>{ctCollarType}</td><td style="background:#eeeeee;">', 
								 fcMessage.get('ui.francecustomer.name'), 
								 '</td><td>{customerName}</td><td style="background:#eeeeee;">', 
								 fcMessage.get('ui.francecustomer.department'), 
								 '</td><td>{customerDepartment}</td></tr>',
								 
								 '<tr><td colspan="8">',
								 //'<img width="120" src="../../_temp/{frontPhotoName}"/>&nbsp;&nbsp;&nbsp;&nbsp;',
								 //'<img width="120" src="../../_temp/{backPhotoName}"/>&nbsp;&nbsp;&nbsp;&nbsp;',
								 '<img width="120" src="../../_temp/{chartName}"/>&nbsp;&nbsp;&nbsp;&nbsp;',
								 '<img width="120" src="../../_temp/{photoName}"/>',
								 '</td></tr>',
								 '</tbody></table>'];
              var itemTpl = new Ext.Template(itemTplMarkup);
            
            Ext.onReady(function(){
                Ext.QuickTips.init();
                Ext.form.Field.prototype.msgTarget = 'side';
                
                //itemTpl.append('productIdentification', piRecord.data);
                
                piZipForm = new Ext.FormPanel({
                    labelAlign: 'left',
                    url: '../../servlet/ProductZipServlet?action=1',
                    frame: true,
                    title: azMessage.get('ui.accessoryzip.edittitle'),
                    bodyStyle: 'padding:5px 5px 5px 5px;margin-top: 2px;',
                    width: '100%',
                    labelWidth: 70,
                    collapsible: true,
                    collapsed: true,
                    reader: new Ext.data.XmlReader({
                        record: 'item'
                    }, [{
                        name: 'id',
                        mapping: 'id'
                    }, {
                        name: 'azId',
                        mapping: 'azId'
                    }, {
                        name: 'azReference',
                        mapping: 'azReference'
                    },{
                        name: 'customerReference',
                        mapping: 'customerReference'
                    },{
                        name: 'unitNumber',
                        mapping: 'unitNumber'
                    }, {
                        name: 'comment',
                        mapping: 'comment'
                    }, {
                        name: 'isDZBuy',
                        mapping: 'isDZBuy'
                    }, {
                        name: 'ctMaterialType',
                        mapping: 'ctMaterialType'
                    }, {
                        name: 'ctCollarType',
                        mapping: 'ctCollarType'
                    }]),
                    items: [{
                        id: 'id',
                        name: 'id',
                        xtype: 'hidden'
                    }, {
                        id: 'azId',
                        name: 'azId',
                        xtype: 'hidden'
                    }, {
                        id: 'piId',
                        name: 'piId',
						value: piRecord.data.id,
                        xtype: 'hidden'
                    }, {
                        layout: 'column',
                        items: [{
                            columnWidth: .25,
                            layout: 'form',
                            items: [{
                                name: 'azReference',
                                id: 'azReference',
                                fieldLabel: azMessage.get('ui.accessoryzip.reference'),
                                xtype: 'textfield',
                                anchor: '86%',
                                allowBlank: false,
                                blankText: message.get('message.edit.noblank'),
                                maxLength: 64,
								readOnly: true,
								emptyText: message.get('message.combo.pleaseselect'),
                                listeners: {
                                    'render': {
                                        fn: function(){
                                            Ext.getCmp('azReference').getEl().on('click', function(){
                                                parent.selectZip(selectZipCallback);
                                            }, this);
                                        },
                                        scope: this
                                    }
                                }
                            }]
                        },{
                            columnWidth: .25,
                            layout: 'form',
                            items: [{
								  id: 'customerReference',
                                  name: 'customerReference',
                                  fieldLabel: message.get('message.edit.customerreference'),
                                  xtype: 'textfield',
                                  anchor: '86%',
							      width: '90%',
                                  blankText: message.get('message.edit.noblank'),
                                  maxLength: 256,
						       readOnly: true
                            }]
                        },{
                            columnWidth: .25,
                            layout: 'form',
                            items: [{
							      id: 'unitNumber',
                                  name: 'unitNumber',
                                  fieldLabel: message.get('message.action.unitnumber'),
                                  decimalPrecision: 0,
                                  xtype: 'numberfield',
                                  allowBlank: false,
                                  anchor: '86%',
							      width: '90%',
                                  blankText: message.get('message.edit.noblank'),
                                  maxLength: 256
                              }]
                        },{
                            columnWidth: .25,
                            layout: 'form',
                            items: [isDZBuyCombo]
                        }]
                    }],
                    
                    buttons: [{
                        text: message.get('message.edit.save'),
                        handler: function(){
                            if (piZipForm.getForm().isValid()) {
                            	document.getElementsByName('isDZBuy')[0].value = isDZBuyCombo.getValue();
                                piZipForm.getForm().submit({
                                    method: 'post',
                                    success: function(form, action){
                                        piZipStore.reload();
                                        messageTip.msg(message.get('message.tip'), message.get('message.edit.successful'));
                                        piZipForm.getForm().reset();
                                    },
                                    failure: function(form, action){
                                        messageTip.msg(message.get('message.tip'), message.get('message.edit.unsuccessful'));
                                    }
                                });
                            }
                        }
                    }, {
                        text: message.get('message.edit.reset'),
                        handler: function(){
                            piZipForm.getForm().reset();
                        }
                    }, {
                        text: message.get('message.edit.cancel'),
                        handler: function(){
                        	if(input == 'history'){
								if (startPage != null) {
	                                parent.window.location = 'product_identification_history_list.html?startPage=' + startPage;
	                            }else {
	                                parent.window.location = 'product_identification_history_list.html';
	                            }
	                            return;
							}
                            if (startPage != null) {
                                parent.window.location = 'product_identification_list.html?startPage=' + startPage;
                            }
                            else {
                                parent.window.location = 'product_identification_list.html';
                            }
                        }
                    }]
                });
                
                
                //piZipForm.render('productIdentificationZipForm');
				
				piZipStore = new Ext.data.Store({
                    url: '../../servlet/ProductZipServlet?action=5&id=' + piRecord.data.id,
                    
                    reader: new Ext.data.XmlReader({
                        record: 'item',
                        id: 'id',
                        totalRecords: 'itemTotal'
                    }, ['index','zipLength', 'id', 'measure', 
						'teethColor', 'comment', 'blockColor','azId','headColor','azReference', 'colorNumber','customerReference','forSize','supplier','variant',
						{
							name:'total',
							type: 'int'
						},{
							name:'stock',
							type: 'int'
						},{
							name:'unitNumber',
							type: 'int'
						}, 'photoName',{
						 	name: 'biFranceCustomer.name',
						 	mapping: 'customerName'
						 }, {
						 	name: 'biFranceCustomer.department',
						 	mapping: 'customerDepartment'
						 }, {
						 	name: 'biFactory.nameCN',
						 	mapping: 'factoryNameCN'
						 }, {
						 	name: 'biFactory.nameEN',
						 	mapping: 'factoryNameEN'
						 },'customerColor', 'factoryColor', 'ctWeaveType', 'ctZipSize', 'ctSlider', 'ctPuller']),
                    
                    sortInfo: {
                        field: 'index',
                        direction: "ASC"
                    }
                });
				var expander = new Ext.grid.RowExpander({
			        tpl : new Ext.XTemplate(
			        	'<p><b>' + azMessage.get('ui.accessoryzip.zipweave') + ':</b>&nbsp;&nbsp;{ctWeaveType}&nbsp;&nbsp;&nbsp;&nbsp;<b>' + azMessage.get('ui.accessoryzip.zipsize') + ':</b>&nbsp;&nbsp;{ctZipSize}&nbsp;&nbsp;&nbsp;&nbsp;<b>' + message.get('message.edit.materialtype') + ':</b>&nbsp;&nbsp;{ctMaille}&nbsp;&nbsp;&nbsp;&nbsp;<b>' + azMessage.get('ui.accessoryzip.slider') + ':</b>&nbsp;&nbsp;{ctSlider}</p><br/> ',
			        	'<br/><p><img src="../../_temp/{photoName}" width="150px" style="cursor: hand;" onclick="parent.openImageViewer(this.src);"/></p>', 
						'<br/><p><b>' + message.get('message.edit.comment') + ':</b> {comment}</p><br/>'
			        )
			    });
				piZipGrid = new Ext.grid.GridPanel({
                    title: azMessage.get('ui.accessoryzip.listtitle'),
                    store: piZipStore,
                    stripeRows: true,
                    height: 200,
                    plugins: [expander],
                    columns: [expander,{
                        header: message.get('message.list.id'),
                        width: 50,
                        dataIndex: 'index',
                        sortable: false
                    },{
                        id: 'azReference',
                        header: azMessage.get('ui.accessoryzip.reference'),
                        dataIndex: 'azReference',
						groupable: false
                    },{
                        header: message.get('message.edit.customerreference'),
                        dataIndex: 'customerReference',
						groupable: false
                    },{
                        header: message.get('message.edit.factoryreference'),
                        dataIndex: 'factoryReference',
						groupable: false
                    },{
                        id: 'unitNumber',
                        header: message.get('message.action.unitnumber'),
                        dataIndex: 'unitNumber',
						groupable: false
                    },{
                        header: aoMessage.get('ui.accessoryothers.forsize'),
                        dataIndex: 'forSize',
						groupable: false,
						renderer: function(value, p, record){
							if(value == 'all'){
								return aoMessage.get('ui.accessoryothers.forall')
							}else{
								return value;
							}
						}
                    },{
                        header: dzColorMessage.get('ui.dzcolor.variant'),
                        dataIndex: 'variant',
						groupable: false,
						renderer: function(value, p, record){
							if(value == 'all'){
								return aoMessage.get('ui.accessoryothers.forall')
							}else{
								return value;
							}
						}
                    },{
                        header:  message.get('message.edit.buyer'),
                        dataIndex: 'supplier',
						groupable: false
                    }
                    /*,{
                        header: message.get('message.list.eidt'),
                        width: 50,
                        dataIndex: 'id',
                        sortable: false,
						groupable: false,
                        renderer: renderEdit
                    },{
                        header: message.get('message.list.delete'),
                        width: 50,
                        dataIndex: 'id',
                        sortable: false,
						groupable: false,
                        renderer: renderDelete
                    }*/],
                     viewConfig: {
                        forceFit: true
                    },
                    loadMask: true,
                    renderTo: 'buttonList'
                });
				
				piZipStore.load();
				
            });
			
			
			function renderEdit(value, p, record){
                    return String.format('<a href="javascript: piZipForm.expand(true);editItem(editCallback, {0});"><img src="../../images/icons/pencil.png" title="Edition" /></a>', record.id);
                }
                
            function renderDelete(value, p, record){
                return String.format('<a href="javascript: deleteItem(deleteCallback, {0});"><img src="../../images/icons/delete.png" title="Supprimer"/></a>', record.id);
            }
			
			var deleteCallback = function(btn){
                if (btn == 'yes') {
                    Ext.Ajax.request({
                        url: '../../servlet/ProductZipServlet?action=2&id=' + deleteId,
                        success: function(o){
                            if (o.responseText == 'success') {
                                piZipStore.reload();
                                messageTip.msg(message.get('message.tip'), message.get('message.delete.successful'));
                            }
                            else {
                                messageTip.msg(message.get('message.tip'), message.get('message.delete.unsuccessful'));
                            }
                        },
                        failure: function(o){
                            messageTip.msg(message.get('message.tip'), message.get('message.delete.failure'));
                        },
                        params: {
                            foo: 'bar'
                        }
                    });
                }
            }
			
			var editCallback = function(){
				piZipForm.getForm().load({
					url:'../../servlet/ProductZipServlet?action=3&id=' + editId, 
					waitMsg:Ext.LoadMask.prototype.msg, 
					success: function(form, action){
						
					}
				});
			}
			
			var selectZipCallback = function(azId, azReference, customerName, customerDepartment, customerReference){
				//alert(azId + ' ' + azReference+ ' ' + zipMeasure+ ' ' + zipLength + ctMaterialType+ ' ' + ctCollarType + ' ' + colorNumber+ ' ' + teethColor + ' ' + blockColor+ ' ' + stock);
        		document.getElementById('azId').value = azId;
				document.getElementById('azReference').value = azReference;
				document.getElementById('customerReference').value = customerReference;
				
				/*
				document.getElementById('azMeasure').value = zipMeasure;
				document.getElementById('azLength').value = zipLength;
				
				document.getElementById('ctMaterialType').value = ctMaterialType;
				document.getElementById('ctCollarType').value = ctCollarType;
				document.getElementById('colorNumber').value = colorNumber;
				document.getElementById('teethColor').value = teethColor;
				document.getElementById('blockColor').value = blockColor;
				document.getElementById('headColor').value = headColor;
				document.getElementById('stock').value = stock;
				*/
        	}
        </script>
    </head>
    <body style="margin: 0 0 0 0;">
        <div id="productIdentification">
        </div>
        <div id="productIdentificationZipForm">
        </div>
        <div id="buttonList" style="margin-top: 5px;">
        </div>
    </body>
</html>
